package math
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import kim.math.ui.Dot;
	
	public class Sphere extends Sprite
	{
		
		private var R:int=150;//球体半径
		private var container:Sprite=new Sprite();//创建容器
		private var _sphereArray:Array = null;	// 球體的數組
		public function Sphere(x:Number, y:Number)
		{
			addChild(container);
			container.x = x;
			container.y = y;
			createSphere();//创建球体分布
			addEventListener(Event.ENTER_FRAME,Run);
		}
		
		private function createSphere():void
		{
			this._sphereArray = [];
			for (var i:int=0; i<180; i+=10)
			{ //纬度
				for (var j:int=0; j<360; j+=10)
				{
					//经度
					var ball:Ball=new Ball();
					this._sphereArray.push(ball);
					container.addChild(ball);
					ball.x=R*Math.sin(i*Math.PI/180)*Math.cos(j*Math.PI/180);
					ball.z=R*Math.sin(i*Math.PI/180)*Math.sin(j*Math.PI/180);
					ball.y=R*Math.cos(i*Math.PI/180);
				}
			}
			
		}
		
		private function Run(event:Event):void
		{
			container.rotationY+=0.2;	
			for each(var ball:Ball in this._sphereArray){
				ball.rotationY += 0.2;
			}
		}
		
	}
}